package com.yuw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuw.bean.AdminInfoBean;
import com.yuw.service.ILoginService;

// @RestController等价于@Controller和@ResponseBody
@RestController
public class RESTFulAction {

	// 依赖注入【反转控制】
	// 面向接口的编程
	@Resource
	private ILoginService loginS;// 按名称匹配进行注入

	@RequestMapping(value = "/adminInfo/{adminId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<AdminInfoBean>> restQueryAdminInfo_GetId(@PathVariable("adminId") Integer adminId) {
		// ResponseEntity<List<AdminInfoBean>> re = new
		// ResponseEntity<List<AdminInfoBean>>(null);
		// 调用service层进行查询操作
		List<AdminInfoBean> lstAdmins = loginS.selectByPrimaryKeyList(adminId);

		// 直接返回查询结果集即可，springmvc框架自动将结果集转换为json字符串返回给客户端
		return ResponseEntity.status(HttpStatus.OK).body(lstAdmins);
	}

	@RequestMapping(value = "/adminInfo/", method = RequestMethod.GET)
	public ResponseEntity<List<AdminInfoBean>> restQueryAdminInfo_GetAll() {
		// ResponseEntity<List<AdminInfoBean>> re = new
		// ResponseEntity<List<AdminInfoBean>>(null);
		// 调用service层进行查询操作
		List<AdminInfoBean> lstAdmins = loginS.selectAllInfos();
		// 直接返回查询结果集即可，springmvc框架自动将结果集转换为json字符串返回给客户端
		return new ResponseEntity<>(lstAdmins, HttpStatus.OK);
		// <> 语法用法，要求maven编译器使用的版本>=1.7，可以在项目右键--> project facets 修改java的版本
		// 也可以使用1.5的版本语法方式
		// return new ResponseEntity<List<AdminInfoBean>>(lstAdmins, HttpStatus.OK);

	}
}